package com.meisiabc.app.repository.db.constant;

import lombok.Getter;
import lombok.ToString;

@Getter
@ToString
public enum ScheduleStatus {
    S0(0, "待上课"),
    S1(1, "无课"),
    S2(2, "学生请假"),
    S3(3, "学生缺席"),
    S4(4, "老师请假"),
    S5(5, "老师缺席"),
    S6(6, "补课"),
    S7(7, "完成"),
    ;

    private int code;
    private String desc;

    ScheduleStatus(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static ScheduleStatus toValue(int code) {
        ScheduleStatus[] items = ScheduleStatus.values();

        for (ScheduleStatus item : items) {
            if (item.getCode() == code) {
                return item;
            }
        }

        return null;
    }

    public static String toDesc(Integer code) {
        if (code == null) {
            return "待上课";
        }

        ScheduleStatus item = toValue(code);
        if (item == null) {
            return String.valueOf(code);
        }

        return item.getDesc();
    }
}
